import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Vuex from 'vuex';
import * as echarts from 'echarts';
import store from './store';

router.beforeEach((to,from,next)=>{
  if (to.matched.some(record => record.meta.requireAuth)){  // 判断该路由是否需要登录权限
    console.log('需要登录');
    if (localStorage.token) {  // 判断当前的token是否存在 ； 登录存入的token
      next();
    }
    else {
      next({
        path: '/',
        query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  }
  else {
    next();
  }
})

Vue.config.productionTip = false;

//需要挂载到Vue原型上
Vue.prototype.$echarts = echarts

Vue.use(ElementUI);
Vue.use(Vuex);


new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')
